package cn.kongwg.dao.impl;

import cn.kongwg.bean.User;
import cn.kongwg.dao.BaseDao;
import cn.kongwg.dao.UserDao;

/**
 * @author kongwg
 * @create 2021-01-22 21:42
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User queryUserByUsername(String username) {

        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ?";

        return queryForOne(User.class, sql, username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username= ? and password = ?";
        return queryForOne(User.class, sql, username, password);
    }

    @Override
    public void saveUser(User user) {
        String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?)";

        update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }
}
